<?php session_start(); ?>
<?php include("../inc/db_config.inc"); ?>
<?php 
$g_title="添加博客";
$g_tab="index";
$stab="blog_add";
$g_header=""; 
$g_js='<script type="text/javascript">
var a="xiaoshan"; 
$(document).ready(function(){
    $("#link").blur(function(){
        if($(this).val()==""){
          return false;
        }
        var url=$(this).val();
        checkLink(url);
    })
})
function checkLink(url,cb){
    $("#checkResult").html("检查中...");
    $.getJSON("blog_add_check.php",{links:url},function(json){
        var Status=json.Status;
        if(Status==1){
            var txt=json.ReturnCode;
            var color="#080";
            getDetail(url);
        }else{
            var txt=json.ReturnCode;
            var color="#f00";
        }
        $("#checkResult").css("color",color).html(txt);
    })
}
function formSubmit(){
    var html=$("#checkResult").html();
    if(html.indexOf("博客地址已存在")!=-1){
        alert("无法提交");
        return false;
    }else{
        return true;
    }
    
}
function getDetail(url){
    $("#loadHolder").html("正在获取博客信息...");
    var url="http://api.zhui.cn/content/List.json?zid=3&ActionID=300&KeyName="+url+"&version=2&SoftVersion=2&jsoncallback=?";
    $.getJSON(url,function(json){
        if(json){
            var status=json.StatusInfo.Status;
            var returncode=json.StatusInfo.ReturnCode;
            if(status==0){
                $("#loadHolder").html(returncode).css("color","#f00");
            }else{
                $("#loadHolder").html(returncode).css("color","#080");
                var CItem=json.CItems[0];
                var zid=CItem.ZID;
                var sid=CItem.ID;
                var title=CItem.Title;
                var description=CItem.Summary;
                
                $("#title").val(title);
                $("#z_zid").val(zid);
                $("#z_sid").val(sid);
                $("#description").val(description);
            }
        }
    })
}
</script>';
?>
 <?php include('header.php'); ?>
			<div class="crumb"></div>
			<div class="main">
				<div class="container r">
					<div class="conbox">
						<div class="cb_hd">
							<span class="cb_tl"></span>
							<span class="cb_tr"></span>
							<h2>添加新博客</h2>
						</div>
						<div class="cb_bd">
								<form onsubmit="return formSubmit();" class="sendbox" action="blog_add_action.php" method="post">
									<p>
										<label>链接地址:</label><input id="link" name="links" class="txt" type="text"/>
                                        <div style="margin-left: 25px;" id="checkResult"></div>
                                        <div style="margin-left: 25px;" id="loadHolder"></div>
									</p>
                                    <p>
										<label>标题:</label><input id="title" name="title" class="txt" type="text"/>
									</p>
									<p>
										<label>分类:</label><select name="cata"><option value="">请选择</option>
										<?php
                                         $result_type=mysql_query("select * from blog_cata");
                                         while($row_type=mysql_fetch_array($result_type)){
                                         ?>
                                            <option value="<?php echo $row_type['id']; ?>"><?php echo $row_type['name']; ?></option>
                                            <?php } ?>
										</select>
									</p>
									
									<p>
										<label>简介:</label><textarea id="description" name="description"></textarea>
									</p>
                                    <p>
										<label>ZID:</label><input id="z_zid" name="z_zid" type="text"/>
									</p>
                                    <p>
										<label>SID:</label><input id="z_sid" name="z_sid" type="text"/>
									</p>
                                    <p>
										<label>分页:</label><input name="z_ps" type="text" value="10"/>
									</p>
									<p>
										<label>联系人:</label><input name="contact" type="text"/>
									</p>
									<p>
										<input class="sub" type="submit" value="提交"/>
									</p>
								</form>
						</div>
						<div class="cb_ft"></div>
					</div>
				</div>
				<?php include('sidebar.php'); ?>
				<div class="c"></div>
			</div>
		</div>
	</div>
<?php include('footer.php'); ?>